home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Think Class Libraries / SAT-TCL 1.0b2 / CGameClasses ƒ / CGameSwitchboard.p < prev    next >
Encoding:
Text File  |  1996-06-10  |  4.0 KB  |  149 lines  |  [TEXT/PJMM]

  1. {****************************************************}
  2. {}
  3. {    CGameSwitchboard.p                                                                                        }
  4. {}
  5. {    Switchboard class, optimized to the needs of gameplay.                                    }
  6. {}
  7. {    For a real game, you may want to override the Game Switchboard further,    }
  8. {    so that mouse clicks, instead of being dispatched to pull down menus etc.,        }
  9. {    are sent to the gopher as triggers for the ships laser guns (say).                    }
  10. {}
  11. {****************************************************}
  12.  
  13.  
  14. unit CGameSwitchboard;
  15.  
  16. interface
  17.  
  18.     uses
  19.         TCL, GameIntf;
  20.  
  21. implementation
  22.  
  23.  
  24. {****************************************************}
  25. {}
  26. {    IGameApp                                                                                                        }
  27. {}
  28. {    Initializes a Game Switchboard object.                                                            }
  29. {}
  30. {****************************************************}
  31.  
  32.     procedure CGameSwitchboard.IGameSwitchboard;
  33.  
  34.     begin { IGameSwitchboard }
  35.         ISwitchboard;
  36.  
  37.         { Start as a normal, everyday Macintosh application. }
  38.         isInGameMode := FALSE;
  39.  
  40.         { Default to being background friendly, like a normal TCL application. }
  41.         isBackgroundFriendly := TRUE;
  42.     end; { IGameSwitchboard }
  43.  
  44.  
  45. {****************************************************}
  46. {}
  47. {    SetInGameMode                                                                                                }
  48. {}
  49. {    Set the game mode.                                                                                        }
  50. {}
  51. {****************************************************}
  52.  
  53.     procedure CGameSwitchboard.SetInGameMode (aInGameMode: Boolean);
  54.  
  55.     begin { SetInGameMode }
  56.         isInGameMode := aInGameMode;
  57.     end; { SetInGameMode }
  58.  
  59.  
  60. {****************************************************}
  61. {}
  62. {    GetBackgroundFriendly                                                                                    }
  63. {}
  64. {    Get the current background friendliness.                                                        }
  65. {}
  66. {****************************************************}
  67.  
  68.     function CGameSwitchboard.GetBackgroundFriendly: Boolean;
  69.  
  70.     begin { GetBackgroundFriendly }
  71.         GetBackgroundFriendly := isBackgroundFriendly;
  72.     end; { GetBackgroundFriendly }
  73.  
  74.  
  75. {****************************************************}
  76. {}
  77. {    SetBackgroundFriendly                                                                                    }
  78. {}
  79. {    Set the background friendliness.                                                                    }
  80. {}
  81. {****************************************************}
  82.  
  83.     procedure CGameSwitchboard.SetBackgroundFriendly (aBackgroundFriendly: Boolean);
  84.  
  85.     begin { SetBackgroundFriendly }
  86.         isBackgroundFriendly := aBackgroundFriendly;
  87.     end; { SetBackgroundFriendly }
  88.  
  89.  
  90. {****************************************************}
  91. {}
  92. {    GetAnEvent                                                                                                    }
  93. {}
  94. {    Gets an event, subject to background friendliness.                                            }
  95. {}
  96. {****************************************************}
  97.  
  98.     function CGameSwitchboard.GetAnEvent (var macEvent: EventRecord): Boolean;
  99.  
  100.     begin { GetAnEvent }
  101.         if isBackgroundFriendly then begin
  102.             GetAnEvent := inherited GetAnEvent(macEvent);
  103.         end { if }
  104.         else begin
  105.             { A more obvious approach would be to use GetOSEvent. However, }
  106.             { in spite of what THINK Reference implies, this filters out high }
  107.             { level events; in particular update events. This means that our }
  108.             { windows won't be updated, which is not good. }
  109.             { The next best thing to do is to set a zero sleep time, so no time }
  110.             { is given to background processes. }
  111.             gSleepTime := 0;
  112.             GetAnEvent := inherited GetAnEvent(macEvent);
  113.         end; { else }
  114.     end; { GetAnEvent }
  115.  
  116.  
  117. {****************************************************}
  118. {}
  119. {    ProcessEvent                                                                                                }
  120. {}
  121. {    Process event, subject to the requirement that a Dawdle message be                }
  122. {    sent to the Game Director on each iteration of the event loop.                            }
  123. {    It is assumed that during game play, the Game Director has sole                        }
  124. {    control the appearance of the mouse; that is, the automatic configuring            }
  125. {    of the mouse by TCL can be omitted.                                                                }
  126. {}
  127. {****************************************************}
  128.  
  129.     procedure CGameSwitchboard.ProcessEvent;
  130.  
  131.         var
  132.             macEvent: EventRecord;
  133.  
  134.     begin { ProcessEvent }
  135.         if not isInGameMode then begin
  136.             inherited ProcessEvent;
  137.         end
  138.         else begin
  139.             if GetAnEvent(macEvent) then begin
  140.                 DispatchEvent(macEvent)
  141.             end; { if }
  142.  
  143.             { The Game Director is called to iterate game play in this next call. }
  144.             DoIdle(macEvent);
  145.         end;
  146.     end; { ProcessEvent }
  147.  
  148.  
  149. end. { CGameSwitchboard }